package com.dfiov.cloud.msmtools.controller;

import com.dfiov.cloud.msmtools.service.AccountLoginAuthService;
import com.dfiov.cloud.msmtools.utils.ResponseUtils;
import com.dfiov.cloud.msmtools.vo.AccountLoginAuthVo;
import com.pateo.qingcloud.framework.common.base.BaseRestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 *@Title AccountLoginAuthController
 *
 *@author xuyz
 *@create 2025/2/20 19:09
 *@description
 */
@RestController
@RequestMapping("/user/accountLoginAuth")
@Api(value = "accountLoginAuth", description = "自有用户登录鉴权接口")
public class AccountLoginAuthController {
    private static final Logger log = LoggerFactory.getLogger(AccountLoginAuthController.class);

    @Autowired
    private AccountLoginAuthService accountLoginAuthService;

    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ApiOperation(value = "更新登录鉴权信息", httpMethod = "PUT", response = BaseRestResponse.class, notes = "更新登录鉴权信息")
    public BaseRestResponse<AccountLoginAuthVo> update(
            @ApiParam(required = true, name = "LoginId", value = "用户登录Id") @RequestParam String LoginId ,
            @ApiParam(required = true, name = "LoginType", value = "登录方式") @RequestParam Short LoginType,
            @ApiParam(required = true, name = "ProjectId", value = "项目Id(pateo/mivi/dnaivi/dfpvivi)") @RequestParam String ProjectId) throws Exception {

        boolean isOk = accountLoginAuthService.update(LoginId, LoginType, ProjectId);
        AccountLoginAuthVo accountLoginAuthVo = accountLoginAuthService.findByLoginTypeAndLoginId(LoginType, LoginId, ProjectId);
        if (isOk) {
            return ResponseUtils.success(accountLoginAuthVo);
        } else {
            return ResponseUtils.fail(accountLoginAuthVo);
        }
    }

    @RequestMapping(value = "/updateDefault", method = RequestMethod.PUT)
    @ApiOperation(value = "更新登录鉴权信息(默认密码)", httpMethod = "PUT", response = BaseRestResponse.class, notes = "更新登录鉴权信息（默认密码）")
    public BaseRestResponse<AccountLoginAuthVo> updateDefault(
            @ApiParam(required = true, name = "LoginId", value = "用户登录Id") @RequestParam String LoginId ,
            @ApiParam(required = true, name = "LoginType", value = "登录方式") @RequestParam Short LoginType,
            @ApiParam(required = true, name = "ProjectId", value = "项目Id(pateo/mivi/dnaivi/dfpvivi)") @RequestParam String ProjectId) throws Exception {

        boolean isOk = accountLoginAuthService.updateDefault(LoginId, LoginType, ProjectId);
        AccountLoginAuthVo accountLoginAuthVo = accountLoginAuthService.findByLoginTypeAndLoginId(LoginType, LoginId, ProjectId);
        if (isOk) {
            return ResponseUtils.success(accountLoginAuthVo);
        } else {
            return ResponseUtils.fail(accountLoginAuthVo);
        }
    }
}
